﻿//读文件到内存中，再内存中操作
int ReadBookFile(const char* pcMode)
{
	int BookRecond = 0;
	FILE* pfBook;//文件指针
	pfBook = fopen("book.txt", pcMode);
	if (pfBook == NULL)
	{
		return -1;
	}
	while (!feof(pfBook))//读文件末尾
	{
		if (fread(&astBook[BookRecond], LEN_BOOK, 1, pfBook))
		{
			BookRecond++;
		}
	}
	fclose(pfBook);
	return BookRecond;
}

//显示图书信息
void ShowBook()
{
	int BookRecord;//记录条数
	system("cls");
	BookRecord = ReadBookFile("rb");//读文件
	if (BookRecord == -1)
	{
		cout << "\t文件打开失败，请添加图书信息" << endl;

	}
	if (BookRecord == 0)
	{
		cout << "\t文件中没有图书信息" << endl;

	}
	else
	{
		cout << endl << "\t**********************************************************" << endl << endl << endl;
		cout << "\t\t" << "编号" << "\t书名" << "\t作者" << "\t出版社" << "\t库存" << endl;
		for (int i = 0; i < BookRecord; i++)
		{
			cout << "\t\t" << astBook[i].Num << "\t" << astBook[i].Name << "\t" << astBook[i].Auther << "\t" << astBook[i].Press << "\t" << astBook[i].Amount << endl;

		}
		cout << endl << endl << "\t**********************************************************" << endl;

	}
}